package com.yufei.infoExtractor.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.core.io.FileSystemResource;

public class ResourceUtil {
final static String classPath_url_prefix="classpath:";
final static String urlPath_url_prefix="http";
final static String filePath_url_prefix="file:";
public static InputStream getResourceAsInputStream(String resourceUrl) throws IOException{
	InputStream  inputStream=null;
	Resource resource=null;
	if(resourceUrl.startsWith(classPath_url_prefix)){
		resource=new ClassPathResource(resourceUrl.substring(classPath_url_prefix.length()));
	}
	if(resourceUrl.startsWith(urlPath_url_prefix)){
		resource=new UrlResource(resourceUrl.substring(urlPath_url_prefix.length()));
	}
	if(resourceUrl.startsWith(filePath_url_prefix)){
		resource=new FileSystemResource(resourceUrl.substring(filePath_url_prefix.length()));
	}
	inputStream=resource.getInputStream();
	return inputStream;
}
}
